<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Mother extends MY_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    
    public function getInfoNotification()
    {
        return json_decode($this->db->query('SELECT * FROM html WHERE id = 3')->row_object()->htmlcontent);
    }
    
    public function getintro()
    {
        return $this->db->query('SELECT * FROM intro WHERE id = 1')->row_object();
    }
    
    public function getInfoContentRight()
    {
        return $this->db->query('SELECT * FROM html WHERE element = 1 AND stt = 1 ORDER BY order_by ASC')->result_object();
    }
    public function getInfofooter()
    {
        return $this->db->query('SELECT * FROM html WHERE element = 100')->row_object();
    }
    
    public function getCright($id)
    {
        return $this->db->query('SELECT * FROM html WHERE id = '.$id)->row_object();
    }
    public function sortsaveDB($id_list)
    {
        foreach($id_list AS $key=>$val)
        {
            $this->db->update('html', array('order_by' => $key), "id = '".$val."'");   
        }
        return 200;    
    }
    public function deleteCright($id)
    {
        $this->db->delete('html', 'id = '.$id);
    }
    
    public function getInfoship()
    {
        return $this->db->query('SELECT * FROM html WHERE id = 7')->row_object();
    }
    
    public function addship()
    {
        $this->db->update('html', array('htmlcontent' => addslashes($_REQUEST['content'])), "id = 7");
    }
    
    public function getInfoIntroIndex()
    {
        return json_decode($this->db->query('SELECT * FROM html WHERE id = 5')->row_object()->htmlcontent);
    }
    
    
    public function addfooter()
    {
        $this->db->update('html', array('htmlcontent' => addslashes($_POST['content'])), "element = 100");
    }
    public function addContentRight()
    {
        $sontent = isset($_POST['content']) ? addslashes($_POST['content']) : '&nbsp;';
        $data = array(
                    'title' => $this->getParamString('title'),
                    'htmlcontent' => $sontent,
                    'element'   => 1
                );
        $this->db->insert('html', $data);
        return 200;
    }
    
    public function editContentRight($id)
    {
        $sontent = isset($_POST['content']) ? addslashes($_POST['content']) : '&nbsp;';
        $data = array(
                    'title' => $this->getParamString('title'),
                    'htmlcontent' => $sontent
                );
        $this->db->update('html', $data, "id = ".$id);
        return 200;
    }
    
    public function addInfoNotification()
    {
        $arr = json_encode(
                array(
                    'notifi' => addslashes($_REQUEST['content']),
                    'hotline'   => $this->getParamString('hotline')
                )
        );
        $this->db->update('html', array('htmlcontent' => $arr), "id = 3");
    }
    public function addintro($img)
    {
        $title = $this->getParamString('title');
        $title_ascii = $this->get_ascii($title);
        
        $title_seo = $this->getParamString('title_seo');
        $title_seo_ascii = $this->get_ascii($title_seo);
        
        $description_seo = $this->getParamString('description_seo');
        $description_seo_ascii = $this->get_ascii($description_seo);
        $arr = array(
                    'content' => addslashes($_REQUEST['content']),
                    'title'   => $title,
                    'title_ascii'   => $title_ascii,
                    'title_seo'   => $title_seo,
                    'title_seo_ascii'   => $title_seo_ascii,
                    'description_seo'   => $description_seo,
                    'description_seo_ascii'   => $description_seo_ascii,
                    
                );
        if(!in_array($img, array(null, '', '0')))
        {
            $arr['img']   = $img;
        }
        $this->db->update('intro', $arr, "id = 1");
    }
    
    
    public function addIntroIndex()
    {
        $arr = json_encode(
                array(
                    'content1' => addslashes($_REQUEST['content']),
                    'content2'   => addslashes($_REQUEST['content2']),
                )
        );
        $this->db->update('html', array('htmlcontent' => $arr), "id = 5");
    }
    
    public function getTopicHot()
    {
        return $this->db->query('SELECT * FROM topic_hot ORDER BY order_by ASC')->result_object();
    }
    
    public function sortsaveTopicDB($id_list)
    {
        foreach($id_list AS $key=>$val)
        {
            $this->db->update('topic_hot', array('order_by' => $key), "id = '".$val."'");   
        }
        return 200;    
    }
    
    public function getTopicID($id)
    {
        return $this->db->query('SELECT * FROM topic_hot WHERE id = '.$id)->row_object();
    }
    
    public function getLink($id)
    {
        $data = $this->db->query('SELECT * FROM content ORDER BY id ASC')->result_object();
        $html  = '<select class="form-control" id="standard-list1" name="link_all">
                          <option value="">Chọn bài viết</option>';
        foreach($data AS $el=>$le)
        {
            if($id == $le->id)
            {
                $selected = 'selected="selected"';
            }else{
                $selected = '';
            }
            $html .= '<option value="'.$le->id.'" '.$selected.'>'.$le->title.'</option>';
        }
        $html .= '</select>';
        return $html;
    }
    
    
    public function editTopicDb($id)
    {
        $ids = $this->getParamInt('link_all');
        $title= $this->db->query('SELECT title FROM content WHERE id = '.$ids)->row_object()->title;
        $data = array(
                'title' => $title,
                'id_content'    => $ids,
                'stt'    => $this->getParamInt('statusTP'),
                );
        $this->db->update('topic_hot', $data, "id = ".$id);
        return 200;
    }
    
    /**
     * 
     *  
     * hỗ trợ
     */
     
     public function getsupportHot()
    {
        return $this->db->query('SELECT * FROM support ORDER BY order_by ASC')->result_object();
    }
    
    public function sortsaveSupportDB($id_list)
    {
        foreach($id_list AS $key=>$val)
        {
            $this->db->update('support', array('order_by' => $key), "id = '".$val."'");   
        }
        return 200;    
    }
    
    public function getsupportHotID($id)
    {
        return $this->db->query('SELECT * FROM support WHERE id = '.$id)->row_object();
    }
    
    
    public function editsupportDb($id)
    {
        $content = $this->getParamString('content');
        $data = array(
                'content'    => $content,
                'type_c'    => $this->getParamInt('TypeSupport'),
                );
        $this->db->update('support', $data, "id = ".$id);
        return 200;
    }
    
    public function selectTypeSupport($id)
    {
        $arr = array('yahoo', 'skype', 'Điện thoại');
        $html  = '<select class="form-control" id="standard-list1" name="TypeSupport">
                          <option value="">Chọn kiểu hỗ trợ</option>';
        foreach($arr AS $el=>$le)
        {
            if($id == $el)
            {
                $selected = 'selected="selected"';
            }else{
                $selected = '';
            }
            $html .= '<option value="'.$el.'" '.$selected.'>'.$le.'</option>';
        }
        $html .= '</select>';
        return $html;
    }
    
    public function addsupportDb()
    {
        $content = $this->getParamInt('content');
        $data = array(
                'content'    => $content,
                'type_c'    => $this->getParamInt('TypeSupport'),
                );
        $this->db->insert('support', $data);
        return 200;
    }
    
    public function deletesupportdb($id)
    {
        $this->db->delete('support', 'id = '.$id);
    }
}